
/**
 * Module dependencies.
 */

var express = require('express')
  , login = require('./routes/login')
  , event = require('./routes/event')
  , http = require('http')
  , path = require('path')
  , connect = require('express/node_modules/connect')
  , socket = require('core/socket')
  , authorization = require('core/authorization');

var app = express();
var sessionStore = new connect.session.MemoryStore();

app.configure(function(){
  app.set('port', process.env.PORT || 3000);
  app.set('views', __dirname + '/views');
  app.set('view engine', 'jade');
  app.use(express.favicon());
  app.use(express.logger('dev'));
  app.use(express.bodyParser());
  app.use(express.cookieParser());
  //app.use(express.session({ secret: 'keyboard cat', cookie: { maxAge: 60000 } }));
  app.use(express.session({ key: 'express.sid', secret: 'keyboard cat', store: sessionStore}));
  app.use(express.methodOverride());
  app.use(app.router);
  app.use(express.static(path.join(__dirname, 'public')));
});

app.configure('development', function(){
  app.use(express.errorHandler({dumpExceptions: true, showStack: true}));
  app.locals.pretty = true;
});
app.configure('production', function(){
  app.use(express.errorHandler());
});

app.get('/', authorization.accept('anonymous'), event.home);
app.get('/login', login.get);
app.post('/login', login.post);
app.get('/event/create', authorization.accept('anonymous'), event.create);
app.get('/event/:name', authorization.accept('anonymous'), event.get);
app.post('/event/create', authorization.accept('anonymous'), event.post);
app.get('/event/create/:name', authorization.accept('anonymous'), event.createTrack);

var server = http.createServer(app).listen(app.get('port'), function(){
  console.log("Express server listening on port " + app.get('port'));
});

socket.listen(server, sessionStore, 'keyboard cat'); 



